<?php

/**
 * Introduction: 活动
 * @author: 杨陈鹏
 * @email: yangchenpeng@cdlinglu.com
 */

namespace Admin\Controller\Activity;

use Common\Controller\Admin\CommonController;

class IndexController extends CommonController
{
    /**
     * Introduction: 活动列表
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     */
    public function lists()
    {

        $logic = D('Common/Activity','Logic');

        $this->page = I('post.page',1);

        $this->nums = 20;

        $this->status = I('param.status',false);

        $where = '';

        switch($this->status){

            case 1:

                    $where = "end_time > ".NOW_TIME;

                break;

            case 2:

                    $where = "end_time < ".NOW_TIME;

                break;

        }

        $data = $logic::getData($where,'*','create_time desc', $this->page, $this->nums);

        $this->data = $data['data'];

        $this->total = $data['total'];

        $this->display();
    }

    /**
     * Introduction: 获取秀图列表
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     */
    public function showList()
    {

        $this->activity_id = I('post.id');

        $this->page = I('post.page',1);

        $this->pu = I('post.pu');

        $this->nums = 20;


        $logic = D('Common/Activity','Logic');

        $data = $logic::showLists($this->activity_id,'*','create_time desc',$this->page,$this->nums);

        $this->data = $data['data'];


        if(!$this->data)
            $this->ajaxReturn(['code' => 300,'msg' => '暂无数据!']);

        $this->total = $data['total'];


        $this->display();



    }

    /**
     * Introduction: 修图评论
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     */
    public function commentLists()
    {
        $this->show_id = I('post.id');

        $logic = D('Common/Activity','Logic');

        $data = $logic::showCommentLists($this->show_id);

        $this->data = $data['data'];

        if(!$this->data)
            $this->ajaxReturn(['code' => 300,'msg' => '暂无数据!']);

//        echo  '<pre>';
//
//        var_dump($this->data);
//        exit;

        $this->display();


    }
    /**
     * Introduction: 删除秀图评论
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     */
    public function deleteShowComment()
    {

        $id = I('post.id');

        $logic = D('Common/Activity','Logic');

        if($logic::$model_show_comment->where(['id' => $id])->delete())
            $this->ajaxReturn(['code' => 200 ,'msg' => '删除成功']);

        $this->ajaxReturn(['code' => 300 ,'msg' => '删除失败']);


    }

    /**
     * Introduction: 删除修图
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     */
    public function deleteShow()
    {

        $id = I('post.id');

        $logic = D('Common/Activity','Logic');

        if($logic::$model_show->where(['id' => $id])->delete())
            $this->ajaxReturn(['code' => 200, 'msg' => '删除成功']);

        $this->ajaxReturn(['code' => 300, 'msg' => '删除失败']);


    }
    /**
     * Introduction: 发布活动
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     */
    public function create()
    {

        $data = I('post.data','',false);

        if($data)
        {

            $logic = D('Common/Activity','Logic');

            //exit($logic::create($data));
            $this->ajaxReturn($logic::create($data));

        }

        $this->display();

    }
    /**
     * Introduction: 修改活动
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     */
    public function update()
    {

        $data = I('post.data','',false);

        $this->id = I('post.id');

        $this->page = I('post.page');

        $logic = D('Common/Activity','Logic');

        if($data)
        {

            $this->ajaxReturn($logic::update(['id' => $data['id']],$data));


        }

        $data = $logic::getOneData($this->id);

        $this->data = $data['data'];

//        echo '<pre>';
//
//        var_dump($this->data);
//
//        exit;

        $this->display();

    }


}